/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package clusteranalyst2;

/**
 *
 * @author Administrator
 */
import Control.CCache;
import java.util.ArrayList;

/**
 *
 * @author jlh
 */
public class GetSimilarClass {

    public int basicID;
    public double level = 0.81;
    public double Plevel;
/**
 *
 * @param HID
 * @return
 */
    public ArrayList getsimilarClass(int HID) {
        ArrayList similarAl = new ArrayList();
        //获取ClassID的第一个值作为判断父节点是否有子节点的标准，如果子节点的值大于这个标准，就说明其仍然拥有子节点
        this.basicID = CCache.getCache().getMinParent();
        //查找与输入类别归属于同一类的类ID
        this.Plevel = CCache.getCache().getChildren(HID).getEvalue();
        similarAl.add(CCache.getCache().getChildren(HID).getEchild1());
        similarAl.add(CCache.getCache().getChildren(HID).getEchild2());

        //将similarAL中的值实例化成Parent类，判断是否存在Children，如果存在就放到新的arraylist中
        if (Plevel > level) {
            System.out.println("没有找到相似的房屋");
            similarAl.clear();
        } else {
            while (similarAl.size() > 0) {
                ArrayList al = new ArrayList();
                int count = 0;
                int[] childrenI = new int[2];
                for (int i = 0; i < similarAl.size(); i++) {
                    Parent parent = new Parent(Integer.parseInt(similarAl.get(i).toString()));
                    if (parent.hasChildren(basicID)) {
                        childrenI = parent.getChildren();
                        System.out.println("Children:" + childrenI[0]);
                        System.out.println("Children:" + childrenI[1]);
                        al.add(childrenI[0]);
                        al.add(childrenI[1]);
                    } else {
                        count++;
                        System.out.println(similarAl.get(i).toString() + "  has no children");
                        al.add(Integer.parseInt(similarAl.get(i).toString()));
                    }

                }
                if (count == similarAl.size()) {
                    break;
                } else {
                    similarAl.clear();
                    similarAl = al;
                }
            }
        }
        return similarAl;
    }
    /**
     * 测试用
     * @param args
     */
    public static void main(String[] args) {
        GetSimilarClass gsc = new GetSimilarClass();
        ArrayList aaAl = gsc.getsimilarClass(902);
        for (int i = 0; i < aaAl.size(); i++) {
            System.out.print("  " + aaAl.get(i).toString());
        }

    }
}